<?php
pc_base::load_app_class('hchbase','hchindex',0);
class index extends hchbase {
	function __construct() {
		parent::__construct();
		$this->dbCrowdfunding = pc_base::load_model("mycrowdfunding_model");
		$this->dbComment = pc_base::load_model("mycomment_model");
		$this->menuList = array(
			'crowdfunding'=>array('name'=>'聚天使众筹','url'=>'/index.php?m=hchbrowse&c=index&a=pageList&action=crowdfunding','index'=>'crowdfunding'),
			'roadshow'=>array('name'=>'路演大厅','url'=>'/index.php?m=hchbrowse&c=index&a=imageList&action=roadshow','index'=>'roadshow'),
			'3'=>array('name'=>'俱乐部活动','url'=>'/index.php?m=hchbrowse&c=index&a=activity','index'=>'activity')
		);
		
		$this->bulletInfo0 = '华创俱乐部 HCCLUB';
		$this->bulletInfo1 = '创业活动';
	}

	function imageList(){
		$page = isset($_GET['page']) && intval($_GET['page']) ? intval($_GET['page']) : 1;
		$subId = $_GET['sub_id']?$_GET['sub_id']:0;
        $action = $_GET['action']?$_GET['action']:'roadshow';
        $this->bulletInfo2 = $this->menuList[$action]['name'];
        $curURL = $this->menuList[$action]['url'];
        
        if($subId==0){
        	$whereSql = ' is_del=0 AND (assort_type_id=33 OR assort_type_id=34)';
			$orderSql = " id DESC";
	        $lists = $this->db->listinfo($whereSql,$orderSql,$page,6);
			$pages = $this->db->pages;
        	        	 
			include template ( 'content/browse', 'image_list' );
        }else{
        	$whereSql = array('id'=>$subId);
        	$info = $this->db->get_one($whereSql,'*');
        	$infoId = $info['id'];
        	$browse = $info['browse_times'];
        	$isBrowse = true;
        	$info['content'] = htmlspecialchars_decode($info['content']);
        	if($info['assort_type_id'] == 34){
	        	$whereSql = array('project_id'=>$subId,'is_del'=>0,'comment_type'=>2);
	        	$orderSql = " id DESC";
	        	$commentLists = $this->dbComment->listinfo($whereSql,$orderSql,$page,10);
	        	$pages = $this->dbComment->pages;
        		include template ( 'content/loadshow', 'video_view' );
        	}else{
        		include template ( 'common', '_item' );
        	}
        }
	}
	
	function pageList(){
		$page = isset($_GET['page']) && intval($_GET['page']) ? intval($_GET['page']) : 1;
		$subId = $_GET['sub_id']?$_GET['sub_id']:0;
        $action = $_GET['action']?$_GET['action']:'crowdfunding';
        $this->bulletInfo2 = $this->menuList[$action]['name'];
        $curURL = $this->menuList[$action]['url'];
        
        if($subId==0){
			$whereSql = array('is_show'=>1,'is_del'=>0);
	        $orderSql = " last_updated_time DESC";
	        $lists = $this->dbCrowdfunding->listinfo($whereSql,$orderSql,$page,10);
			$pages = $this->dbCrowdfunding->pages;
        	 
			include template ( 'content/crowdfunding', 'page_list' );
        }else{
			$crowdfunding = $this->dbCrowdfunding->get_one(array('id'=>$subId,'is_show'=>1),'*');
			if(empty($crowdfunding) || count($crowdfunding)<=0 ){
				showmessage("项目不存在或未审核！请浏览其他项目。",$curURL);
			}
        	if(!empty($_GET['key'])){
        		$key = $_GET['key'];
        	}else{
        		$key = 'product_introduction';
        	}
        	$whereSql = array('id'=>$crowdfunding[$key],'is_del'=>0);
        	$info = $this->db->get_one($whereSql,'*');
        	if($key == 'product_introduction'){
	        	if(empty($info) || count($info)<=0 ){
	        		$info = $crowdfunding;
	        	}
        	}else{
        		if(empty($info) || count($info)<=0 ){
        			$info['name'] = $crowdfunding['name'];
        		}
        	}
        	
        	$infoId = $crowdfunding['id'];
        	$browse = $crowdfunding['browse_times'];
        	$isCrowdfunding = true;
        	$info['content'] = htmlspecialchars_decode($info['content']);
        	
        	$whereSql = array('project_id'=>$subId,'is_del'=>0,'comment_type'=>1);
        	$orderSql = " id DESC";
        	$commentLists = $this->dbComment->listinfo($whereSql,$orderSql,$page,10);
        	$pages = $this->dbComment->pages;
        	 
        	$dbUser2Crowdfundging = pc_base::load_model("myuser2crowdfunding_model");
        	$where = array('crowdfunding_id'=>$subId,'relation_type'=>1,'is_del'=>0);
			$inverstorList = $dbUser2Crowdfundging->select($where,'*','');
        	
			$favWhere = array('crowdfunding_id'=>$subId,'relation_type'=>2,'is_del'=>0);
			$favList = $dbUser2Crowdfundging->select($favWhere,'*','');
			$userid = $this->memberinfo['userid'];
			if (count($favList)<=0 && $userid){
				$toFav = true;
			}else{
				$toFav = false;
			}
            if($info['aid']){
                $dbArea = pc_base::load_model("myarea_model");
                $area_info = $dbArea->get_one(array('id'=>$info['aid']));
                $area_name = $area_info['area_name'];
                do{
                    $area_info = $dbArea->get_one(array('area_no'=>$area_info['parent_no']));
                    $area_name = $area_info['area_name'].' '.$area_name;
                }while($area_info['area_level']>1);
                $info['area_name'] = $area_name;
            }else{
                $info['area_name'] = '';
            }

        	include template ( 'content/crowdfunding', '_item' );
        }
	}
	

	function activity(){
		$page = isset($_GET['page']) && intval($_GET['page']) ? intval($_GET['page']) : 1;
		$subId = $_GET['sub_id']?$_GET['sub_id']:0;
		$action = 'activity';
		$this->bulletInfo2='俱乐部活动';
		$curURL = $this->menuList[3]['url'];
	
		if($subId==0){
			$whereSql = " parent=2 AND name='activity'";
			$type = $this->dbType->get_one($whereSql,'id');
			$typeId = $type['id'];
			$whereSql = array('assort_type_id'=>$typeId,'is_del'=>0);
			$orderSql = " id DESC";
			$activityList = $this->db->listinfo($whereSql,$orderSql,$page,10);
			$pages = $this->db->pages;
			$activityTpyeId = $typeId;
	
			include template ( 'content/about', 'about_activity_list' );
		}else{
			$whereSql = array('id'=>$subId);
			$info = $this->db->get_one($whereSql,'*');
			$infoId = $info['id'];
			$browse = $info['browse_times'];
			$isBrowse = true;
			$info['content'] = htmlspecialchars_decode($info['content']);
			$isActivity = true;
			$activityUrl = "/index.php?m=hchbrowse&c=index&a=join&activityid=".$infoId;
	
			include template ( 'common', '_item' );
		}
	}
	
	function join(){
		$action = 'activity';
		$this->bulletInfo2='俱乐部活动';
		$curURL = $this->menuList[3]['url'];
		$activityId = $_GET['activityid'];
		$whereSql = array('id'=>$activityId);
		$info = $this->db->get_one($whereSql,'*');
	
		if(!empty($_POST['dosubmit'])){
			$item = $_POST['item'];
			$dbJoin = pc_base::load_model("myjoin_model");
			$item['created_time'] = $this->CURRENT_DATETIME;
			$joinId = $dbJoin->insert($item,true);
			echo"<script>alert('报名成功');window.location.href='".$this->menuList[3]['url']."&sub_id=".$item['activity_id']."';</script>";
		}
		$ismobile = $this->isMobile();
		if(!$ismobile){
			include template ( 'content/about', 'mob' );
		}else{
			include template ( 'content/about', 'join' );
		}
	}
	
	function isMobile(){
		// 如果有HTTP_X_WAP_PROFILE则一定是移动设备
		if (isset ($_SERVER['HTTP_X_WAP_PROFILE'])){
			return true;
		}
		// 如果via信息含有wap则一定是移动设备,部分服务商会屏蔽该信息
		if (isset ($_SERVER['HTTP_VIA'])){
			// 找不到为flase,否则为true
			return stristr($_SERVER['HTTP_VIA'], "wap") ? true : false;
		}
		// 判断手机发送的客户端标志,兼容性有待提高
		if (isset ($_SERVER['HTTP_USER_AGENT'])){
			$clientkeywords = array ('nokia',
					'sony',
					'ericsson',
					'mot',
					'samsung',
					'htc',
					'sgh',
					'lg',
					'sharp',
					'sie-',
					'philips',
					'panasonic',
					'alcatel',
					'lenovo',
					'iphone',
					'ipod',
					'blackberry',
					'meizu',
					'android',
					'netfront',
					'symbian',
					'ucweb',
					'windowsce',
					'palm',
					'operamini',
					'operamobi',
					'openwave',
					'nexusone',
					'cldc',
					'midp',
					'wap',
					'mobile'
			);
			// 从HTTP_USER_AGENT中查找手机浏览器的关键字
			if (preg_match("/(" . implode('|', $clientkeywords) . ")/i", strtolower($_SERVER['HTTP_USER_AGENT'])))
			{
				return true;
			}
		}
		// 协议法，因为有可能不准确，放到最后判断
		if (isset ($_SERVER['HTTP_ACCEPT'])){
			// 如果只支持wml并且不支持html那一定是移动设备
			// 如果支持wml和html但是wml在html之前则是移动设备
			if ((strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') !== false) && (strpos($_SERVER['HTTP_ACCEPT'], 'text/html') === false || (strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') < strpos($_SERVER['HTTP_ACCEPT'], 'text/html'))))
			{
				return true;
			}
		}
		return false;
	}
	
}
?>